using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;

namespace ACP.Tortuga_Package {

	public class SelectedItemCollection : List<SelectedItem> {
		public SelectedItemCollection() : base() { }
		public SelectedItemCollection(IEnumerable<SelectedItem> items) : base(items) { }

		#region Specific Finds
		/// <summary>
		/// Determines if a solution
		/// </summary>
		/// <returns></returns>
		public bool ContainsSolution() {
			SelectedItem i = this.Find(delegate(SelectedItem item) {
				bool b = item is Solution;
				return b;
			});
			return (i != null);
		}

		/// <summary>
		/// Finds all the Projects in this collection.
		/// </summary>
		/// <returns></returns>
		public SelectedItemCollection FindProjects() {
			SelectedItemCollection found = new SelectedItemCollection(this.FindAll(delegate(SelectedItem item) {
				bool b = item is Project;
				return b;
			}));
			return found;
		}

		#endregion



		public List<string> GetSelectedPaths() {
			List<string> paths = new List<string>();
			this.ForEach(delegate(SelectedItem item) {
				if (item != null) {
					object info = "";// item.get_Info(1);
					string fileName = "";
					if (item.ProjectItem == null) {
						if (item.Project == null) {
							// Then we have selected the solution
							paths.Add(SelectedItemHelper.GetSolutionPath(item.DTE.Solution));
							paths.Add(item.DTE.Solution.FullName);
						} else {
							// Then we probably have a Project
							fileName = item.Project.FullName;
							paths.Add(SelectedItemHelper.GetProjectPath(item.Project));
						}
					} else {
						// This is probably a regular file
						fileName = item.ProjectItem.get_FileNames(1);
					}
					paths.Add(fileName);
				}
			});
			return paths;
		}
	}
}
